/**
 * 学生信息管理工具
 */

// 获取学生信息对象
export function getStudentInfo() {
  const studentInfoStr = localStorage.getItem('studentInfo');
  if (studentInfoStr) {
    try {
      return JSON.parse(studentInfoStr);
    } catch (error) {
      console.error('解析学生信息失败:', error);
      return null;
    }
  }
  return null;
}

// 获取学生ID
export function getStudentId() {
  const studentInfo = getStudentInfo();
  return studentInfo ? studentInfo.studentId : localStorage.getItem('studentId');
}

// 获取学生姓名
export function getStudentName() {
  const studentInfo = getStudentInfo();
  return studentInfo ? studentInfo.name : localStorage.getItem('studentName');
}

// 获取学生年级
export function getGradeYear() {
  const studentInfo = getStudentInfo();
  return studentInfo ? studentInfo.gradeYear : localStorage.getItem('gradeYear');
}

// 获取学院
export function getCollege() {
  const studentInfo = getStudentInfo();
  return studentInfo ? studentInfo.college : localStorage.getItem('college');
}

// 获取专业
export function getDepartment() {
  const studentInfo = getStudentInfo();
  return studentInfo ? studentInfo.department : localStorage.getItem('department');
}

// 获取性别
export function getGender() {
  const studentInfo = getStudentInfo();
  return studentInfo ? studentInfo.gender : localStorage.getItem('gender');
}

// 获取状态
export function getStatus() {
  const studentInfo = getStudentInfo();
  return studentInfo ? studentInfo.status : localStorage.getItem('status');
}

// 获取用户名
export function getUsername() {
  const studentInfo = getStudentInfo();
  return studentInfo ? studentInfo.username : localStorage.getItem('username');
}

// 获取用户ID
export function getUserId() {
  return localStorage.getItem('userId');
}

// 检查是否已登录
export function isLoggedIn() {
  return !!getUserId();
}

// 检查是否是学生
export function isStudent() {
  return isLoggedIn() && !!getStudentId();
}

// 清除所有学生信息
export function clearStudentInfo() {
  localStorage.removeItem('studentInfo');
  localStorage.removeItem('studentId');
  localStorage.removeItem('studentName');
  localStorage.removeItem('gradeYear');
  localStorage.removeItem('college');
  localStorage.removeItem('department');
  localStorage.removeItem('gender');
  localStorage.removeItem('status');
  localStorage.removeItem('username');
  localStorage.removeItem('userId');
} 